package com.zhilingshenghuo.app.zhly.view.widget;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;

import com.zhilingshenghuo.app.zhly.R;

public abstract class RulePopwindow {

    private PopupWindow popupWindow;
    private Activity context;

    /**
     * 构造函数
     *
     * @param context
     */
    public RulePopwindow(Activity context) {
        this.context = context;
    }

    /**
     * 显示警示框
     */
    public void show() {
        View popView = View.inflate(context, R.layout.pop_rule, null);
        popupWindow = new PopupWindow(context);
        popupWindow.setAnimationStyle(R.style.popWindow_animation);//设置动画
        popupWindow.setOutsideTouchable(false);
        popupWindow.setBackgroundDrawable(null);
        popupWindow.setFocusable(true);
        popupWindow.setContentView(popView);
        popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
        //关闭
        popView.findViewById(R.id.ivClose).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                onDisMiss();
            }
        });

    }


    /**
     * 消失
     */
    public abstract void onDisMiss();
}
